dapper sql builder where

74

dapper sql builder where -

    using (IDbConnection connection = new SqlConnection(ConnectionString))
    {
        var builder = new SqlBuilder();
        builder.Select("Id");
        builder.Select("FirstName");
        builder.Select("LastName");
        DynamicParameters parameters = new DynamicParameters();
        parameters.Add("@MyParam", id, DbType.Int32, ParameterDirection.Input);
        builder.Where("Id = @MyParam", parameters);
        var builderTemplate = builder.AddTemplate("Select /**select**/ from Authors /**where**/ ");
        var author = connection.Query<Author>(builderTemplate.RawSql, builderTemplate.Parameters).FirstOrDefault();
        return author;
    }

Comments

Submit
0 Comments